import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Preloader {
    static public void main(String args[]) {
        Preloader preloader = new Preloader();
        preloader.start();
        try {
            preloader.get();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }

    private final FutureTask<String> future = new FutureTask<String>(new Callable<String>() {
        @Override
        public String call() throws Exception {
            Thread.sleep((long) (Math.random() * 1000));
            return "product info";
        }
    });
    private final Thread thread = new Thread(future);

    public void start() {
        thread.start();
    }

    public String get() throws InterruptedException, ExecutionException {
        try {
            long start = System.nanoTime();
            String r = future.get();
            long end = System.nanoTime();
            System.out.println((end - start) / 1000);
            return r;
        } catch (ExecutionException e) {
            Throwable cause = e.getCause();
            throw e;
        }
    }
}
